var fs = require('fs');
var path = require('path');
var strformat = require('strformat');

function mkdirs(dir) {
  if (fs.existsSync(dir)) {
    if (fs.statSync(dir).isDirectory()) {
      return;
    }
    throw new Error(strformat("Not a directory: '{0}'", dir));
  }
  var i = dir.lastIndexOf(path.sep);
  if (i < 0) {
    throw new Error(strformat("No parent directory: '{0}'", dir));
  }
  mkdirs(dir.substring(0, i));
  fs.mkdirSync(dir);
}

module.exports = function (dir) {
  if(fs.existsSync(dir)){
    return;
  }
  mkdirs(path.resolve(dir));
}